/** 工单
*/
import request from '@/utils/request'
import { filtersRaw, pageRequsetBody } from '@/utils'

/**
 * 保存
 *@params {object} data
 */
export function postWorkOrderRecord(data) {
  return request({
    url: '/call-center/api/v1/workOrderRecord',
    method: 'POST',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data
  })
}
/**
 * 人员变更
 *@params {array} data
 */
export function putWorkOrderHandler(data) {
  return request({
    url: '/call-center/api/v1/workOrderRecord/changeHandlers',
    method: 'PUt',
    data
  })
}
/** 工单导出 */
export function workOrderExport(data) {
  return request({
    url: '/call-center/api/v1/workOrderRecord/export',
    method: 'POST',
    data,
    responseType: 'blob',
    timeout: 10 * 60 * 1000
  })
}
/** 修改
 *@params {object} data
 */
export function putWorkOrderRecord(data) {
  return request({
    url: '/call-center/api/v1/workOrderRecord',
    method: 'PUT',
    data
  })
}
/** 查询所有
 */
export function getWorkOrderRecord() {
  return request({
    url: '/call-center/api/v1/workOrderRecord',
    method: 'GET'
  })
}
/** 根据id查询
 * @params {number} id 工单id
 */
export function getByIdWorkOrderRecord(id) {
  return request({
    url: `/call-center/api/v1/workOrderRecord/${id}`,
    method: 'GET'
  })
}
/** 删除
 * @params {number} id 工单id
 */
export function deleteWorkOrderRecord(id) {
  return request({
    url: `/call-center/api/v1/workOrderRecord/${id}`,
    method: 'DELETE'
  })
}
/** 抄送
 * @params {object} data
 */
export function postCarbonCopy(data) {
  return request({
    url: `/call-center/api/v1/workOrderRecord/carbonCopy`,
    method: 'PUT',
    data
  })
}

/**
 * 改派
 * @param {body} data obj
 */
export function putWorkOrderReassign(data) {
  return request({
    url: `/call-center/api/v1/workOrderRecord/Reassign`,
    method: 'PUT',
    data
  })
}

/** 批量删除
 * @params {array} ids
 */
export function deleteBatch(ids) {
  return request({
    method: 'DELETE',
    url: '/call-center/api/v1/workOrderRecord/deleteBatch',
    data: {
      ids
    }
  })
}
/** 派工单
 * @params {object} data
 */
export function postDispatch(data) {
  return request({
    method: 'POST',
    url: '/call-center/api/v1/workOrderRecord/dispatch',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: data
  })
}
/** 完结工单
 * @parmas {object} data
 */
export function putFinish(data) {
  return request({
    method: 'PUT',
    url: '/call-center/api/v1/workOrderRecord/finish',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data
  })
}
/** 提交工单处理
 * @parmas {object} data
 */
export function putSubmit(data) {
  return request({
    method: 'PUT',
    url: '/call-center/api/v1/workOrderRecord/submit',
    data
  })
}

/** 同步工单
 * @parmas {object} data
 */
export function postSyncWorkOrder(data) {
  return request({
    method: 'POST',
    url: '/call-center/api/v1/workOrderRecord/syncWorkOrder',
    data
  })
}

/**
 * 工单催办
 * @param {body} data data
 */
export function putUrgeWorkOrder(id) {
  return request({
    url: `/call-center/api/v1/workOrderRecord/urge/${id}`,
    method: 'PUT'
  })
}

// 非cc

/** 非cc提交留言处理信息
 * @params {object} data
 */
export function putOpenWorkOrderRecord(data) {
  return request({
    method: 'PUT',
    url: '/call-center/openapi/v1/workOrderRecord',
    data
  })
}
/** 查询所有
 */
export function getOpenWorkOrderRecord() {
  return request({
    method: 'GET',
    url: '/call-center/openapi/v1/workOrderRecord'
  })
}
/** 根据id查询
 * @params {string} id
 */
export function getByIdOpenWorkOrderRecord(id) {
  return request({
    method: 'GET',
    url: `/call-center/openapi/v1/workOrderRecord/${id}`
  })
}
/** 接收工单
 * @params {object} data
 */
export function postAccept(data) {
  return request({
    method: 'POST',
    url: `/call-center/openapi/v1/workOrderRecord/accept`,
    data
  })
}
/** 查询所有派给B2C的工单 */
export function getForB2C() {
  return request({
    method: 'GET',
    url: '/call-center/openapi/v1/workOrderRecord/forB2C'
  })
}
/** 查询所有派给MSC的工单 */
export function getForMSC() {
  return request({
    method: 'GET',
    url: '/call-center/openapi/v1/workOrderRecord/forMSC'
  })
}
/** 查询所有派给QUP的工单 */
export function getForQUP() {
  return request({
    method: 'GET',
    url: '/call-center/openapi/v1/workOrderRecord/forQUP'
  })
}
/** 查询所有派给TOP的工单 */
export function getForTOP() {
  return request({
    method: 'GET',
    url: '/call-center/openapi/v1/workOrderRecord/forTOP'
  })
}

/**
 * 根据订单ID查询订单详细
 * @param {formData} data 查询条件
 */
export function getWorkOrderDetail(data) {
  return request({
    url: `/call-center/api/v1/workOrderRecord/page`,
    method: 'POST',
    data
  })
}
/**
 * 根据查询是否有未完结工单
 * @param {formData} data 查询条件
 */
export function getHaveWorkOrder(v) {
  const data = {
    filtersRaw: [
      filtersRaw('contactPhone', v, '='),
      filtersRaw('workOrderState', '[0,1,2]', 'in')
    ],
    onlyCountFlag: true,
    pageFlag: false
  }
  return request({
    url: `/call-center/api/v1/workOrderRecord/page`,
    method: 'POST',
    data: pageRequsetBody(data)
  })
}
/**
 * 根据工单编号查详情
 * @param {string} code 工单workOrderCode
 */
export function getWorkOrderByCode(workOrderCode) {
  return request({
    url: `/call-center/api/v1/workOrderRecord/getByCode/${workOrderCode}`,
    method: 'GET'
  })
}

/**
 * 上报异常
 * @param {body} data data
 */
export function reportAbnormal(data) {
  return request({
    url: `/call-center/api/v1/workOrderRecord/reportAbnormal`,
    method: 'PUT',
    data
  })
}

/**
 * 删除附件
 * @param {body} data 附件信息
 */
export function deleteAnnex(data) {
  return request({
    url: `/call-center/api/v1/workOrderRecord/annex`,
    method: 'delete',
    data
  })
}
